home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 4
/
FM Towns Free Software Collection 4 - Disc 1.iso
/
t_os
/
bedit
/
bedit.bas
next >
Wrap
BASIC Source File
|
1991-10-18
|
9KB
|
202 lines
1000 '
1010 ' Binary File Editor BEDIT Ver1.03 1991/08/28
1020 ' Programed by でんちゃん♪
1030 '
1040 ' 電脳わ~るど DW0001
1050 '
1060 DEFLNG A-Z
1070 DIM ASCII$(15),SEC$(2),X_SM(15),Y_SM(15)
1080 DIM BUF_FLG(100),BUF_DAT$(100,2),CSR$(2),MODE$(1)
1090 FOR I=0 TO 100:BUF_FLG(I)=-1:NEXT
1100 CSR$(0)="<":CSR$(1)=">":CSR$(2)=CHR$(254)
1110 MODE$(0)="(HEX MODE)":MODE$(1)="(ASC MODE)"
1120 HEXKEY$="___0Mmミ1Jjモ2Kkネ3Llル4Uuマ5Iiノ6Ooリ777ナ888ニ999ラ"
1130 HEXKEY$=HEXKEY$+"Aa*ヤBb/ユCc+ヨDd-ワEe=セFf.レ"
1140 FOR I=1 TO 17:READ A:CTRL$=CTRL$+CHR$(A):NEXT
1150 DATA 5,8,9,11,12,13,17,18,22,23,26,27,28,29,30,31,127
1160 DEF FNHEX$(D) =RIGHT$("0"+HEX$(D),2)
1170 DEF FNADDR$(D) =RIGHT$("000000"+HEX$(D),7)
1180 DEF FNGET(D$,P) =ASC(MID$(D$,P+1,1))
1190 DEF FNREC$(F$,R)=LEFT$(F$,INSTR(F$,":"))+"("+MID$(STR$(R),2)+")"+ MID$(F$,INSTR(F$,":")+1)
1210 CLS:COLOR 7,0:WIDTH 80,25:CONSOLE 22,2,2
1220 LOCATE 5,0:PRINT "Binary Editor BEDIT Ver1.03"
1230 LOCATE 50,0:PRINT "Programed by でんちゃん♪"
1240 LOCATE 0,2:PRINT " Addr :+0 +1 +2 +3 +4 +5 +6 +7,+8 +9 +A";
1250 PRINT " +B +C +D +E +F:SM < A S C I I >"
1260 PRINT STRING$(76,"-"):A$=SPACE$(7)+":"+SPACE$(23)+","+SPACE$(23)+":"
1270 FOR Y=0 TO 15:PRINT A$:NEXT
1280 PRINT STRING$(76,"-")," Sum";MID$(A$,6);
1290 MX_BUF=-1:BUF_NB=-1:GOSUB *OPEN:GOSUB *MODE_PRINT
1300 GOSUB *CSR_ON:GOSUB *COMMAND:GOTO 1300
1310 '
1320 *OPEN
1330 LOCATE 0,23:LINE INPUT "Filename ? ",FIL$:IF FIL$="" THEN 1330
1340 LOCATE 50,1:PRINT SPC(30)
1350 LOCATE 50,1:PRINT LEFT$("Filename = "+FIL$,30)
1360 OPEN "R",#1,FNREC$(FIL$,256):MX_BLK=LOF(1)
1370 FIELD #1,128 AS SEC$(0),128 AS SEC$(1)
1375 FOR I=0 TO 15:FIELD #1,I*16 AS SEC$(2),16 AS ASCII$(I):NEXT
1380 OPEN "R",#2,FNREC$(FIL$,1):FIELD #2,1 AS SEC$(2):MX_SIZ=LOF(2)
1390 GOSUB *SIZE_PRINT:MX_DAT$="":IF MX_SIZ MOD 256 ELSE *BLOCK_READ
1400 FOR I=MX_BLK*256+1 TO MX_SIZ:GET #2,I:MX_DAT$=MX_DAT$+SEC$(2):NEXT
1410 GOTO *BLOCK_READ
1420 *BLOCK_READ
1430 ON SGN(BLK-MX_BLK)+1 GOTO *MAX_READ,*WORK_READ
1440 ED_FLG=0:GET #1,BLK+1:GOTO *BLOCK_PRINT
1460 *MAX_READ
1470 FOR I=0 TO 1:MID$(SEC$(I),1,128)=STRING$(128,CHR$(0)):NEXT
1480 MID$(SEC$(0),1,128)=MX_DAT$
1490 IF LEN(MX_DAT$)>128 THEN MID$(SEC$(1),1,128)=MID$(MX_DAT$,129)
1500 ED_FLG=0:GOTO *BLOCK_PRINT
1510 *WORK_READ GOSUB *CLS:ED_FLG=0:RETURN
1520 *BLOCK_MOVE
1530 IF ED_FLG ELSE 1590
1540 IF RES=MX_BLK+1 THEN GOSUB *MAX_CHNG
1550 IF RES=MX_BLK THEN GOSUB *MAX_SET:GOTO 1590
1560 IF BUF_NB=-1 THEN MX_BUF=MX_BUF+1:BUF_NB=MX_BUF
1570 FOR I=0 TO 1:BUF_DAT$(BUF_NB,I)=SEC$(I):NEXT:BUF_FLG(BUF_NB)=RES
1580 IF BUF_NB=99 THEN *OVER
1590 IF BLK=MX_BLK+2 OR BLK<0 THEN BLK=RES:GOTO *移禁
1600 BUF_NB=SEARCH(BUF_FLG,BLK):IF BUF_NB>-1 THEN *BUF_READ
1610 GOTO *BLOCK_READ
1620 *BUF_READ
1630 FOR I=0 TO 1:MID$(SEC$(I),1,128)=BUF_DAT$(BUF_NB,I):NEXT
1640 GOTO *BLOCK_PRINT
1650 *MAX_SET
1660 A=MX_SIZ MOD 256:MX_DAT$=LEFT$(SEC$(0),A)
1670 IF A>128 THEN MX_DAT$=MX_DAT$+LEFT$(SEC$(1),A-128)
1680 RETURN
1690 *MAX_CHNG
1700 MX_BUF=MX_BUF+1:BUF_FLG(MX_BUF)=MX_BLK:MX_BLK=MX_BLK+1
1710 A$=STRING$(128,CHR$(0))
1720 BUF_DAT$(MX_BUF,1)=LEFT$(MID$(MX_DAT$,129)+A$,128)
1730 IF LEN(MX_DAT$)>127 THEN A$=""
1740 BUF_DAT$(MX_BUF,0)=LEFT$(MX_DAT$+A$,128):RETURN
1750 *SAVE PRINT "Y"
1760 IF MX_BUF=-1 THEN 1810
1770 FOR J=0 TO MX_BUF
1780 FOR I=0 TO 1:LSET SEC$(I)=BUF_DAT$(J,I):NEXT
1790 PUT #1,BUF_FLG(J)+1
1800 NEXT
1810 A=MX_BLK*256:IF A=MX_SIZ THEN *END
1820 FOR I=A+1 TO MX_SIZ
1830 LSET SEC$(2)=MID$(MX_DAT$,I-A,1):PUT #2,I
1840 NEXT:GOTO *END
1850 *END CLOSE:END
1860 '
1870 *BLOCK_PRINT
1880 FOR X=0 TO 15:Y_SM(X)=0:NEXT:Z_SM=0:Y=0:GOTO *PRINT
1890 *HARF_PRINT
1900 IF Y_SIT=0 THEN *BLOCK_PRINT
1910 Z_SM=0
1920 FOR XP=0 TO 15
1930 Y_SM(XP)=0
1940 FOR YP=0 TO Y_SIT-1
1950 Y_SM(XP)=Y_SM(XP)+FNGET(ASCII$(YP),XP)
1960 NEXT
1970 Z_SM=Z_SM+Y_SM(XP)
1980 NEXT
1990 Y=Y_SIT:GOTO *PRINT
2000 *PRINT
2010 LOCATE 0,Y+4:B=BLK*256
2020 FOR YP=Y TO 15
2030 L$=FNADDR$(B+YP*16):X_SM(YP)=0
2040 FOR XP=0 TO 15
2050 DAT=FNGET(ASCII$(YP),XP):L$=L$+" "+FNHEX$(DAT)
2060 X_SM(YP)=X_SM(YP)+DAT:Y_SM(XP)=Y_SM(XP)+DAT
2070 NEXT
2080 MID$(L$,8,1)=":":MID$(L$,32,1)=",":PRINT L$+":"+FNHEX$(X_SM(YP))
2090 Z_SM=Z_SM+X_SM(YP):YL=YP+4:GOSUB *ASC_PRINT
2100 NEXT
2110 L$=""
2120 FOR X=0 TO 15:L$=L$+" "+FNHEX$(Y_SM(X)):NEXT:MID$(L$,25,1)=","
2130 LOCATE 8,21:PRINT MID$(L$,2)+":"+FNHEX$(Z_SM);:GOTO *KEY_CLR
2140 *SM_PRINT
2150 XL=X_SIT*3+8:YL=Y_SIT+4
2160 LOCATE 56,YL:PRINT FNHEX$(X_SM(Y_SIT))
2170 LOCATE XL,YL:PRINT FNHEX$(CHNG)
2180 LOCATE XL,21:PRINT FNHEX$(Y_SM(X_SIT));
2190 LOCATE 56,21:PRINT FNHEX$(Z_SM);:GOTO *ASC_PRINT
2200 *ASC_PRINT
2205 IF ASC_FLG THEN RETURN
2210 A=YL*19:LINE (480,A)-STEP(136,19),PRESET,,BF
2220 SYMBOL(480,A),ASCII$(YL-4),1,1,7:RETURN
2230 *CSR_ON COLOR 15:GOTO 2250
2240 *CSR_OFF COLOR 7:CLS 1
2250 GOSUB *DAT_GET:Y=Y_SIT+4:A=MODE*2+BEAM
2260 LOCATE X_SIT*3+BEAM+8,Y:PRINT MID$(DAT$,BEAM+1,MODE+1)
2270 SYMBOL(X_SIT*8+480,Y*19),CSR$(A),1,1,2^A,,XOR:RETURN
2280 *SIZE_PRINT LOCATE 61,21:PRINT "FileSize $"+FNADDR$(MX_SIZ);:RETURN
2290 *MODE_PRINT LOCATE 2, 1:PRINT MODE$(MODE):RETURN
2300 *移禁 LOCATE 0,23:PRINT "移行できません":RETURN
2310 *OVER LOCATE 0,23:PRINT "これ以上の編集はできませんので、終了します"
2320 GOTO *EOF
2330 '
2340 *COMMAND
2350 GOSUB *KEY_IN:GOSUB *CSR_OFF
2360 ON INSTR(CTRL$,KEY_DAT$) GOTO *EL,*BS,*TAB,*HOME,*CLS,*CR,*DUP,*INS, *BACK,*NEXT,*EOF,*ESC,*MV_R,*MV_L,*MV_U,*MV_D,*DEL
2370 IF MODE THEN *ASC_SET ELSE *HEX_SET
2380 *EL ED_FLG=1
2390 MID$(ASCII$(Y_SIT),X_SIT+1,16)=STRING$(16,CHR$(0))
2400 BEAM=0:GOTO *HARF_PRINT
2410 *BS ED_FLG=1:P=Y_SIT*16+X_SIT:IF P ELSE 2470
2420 IF P>128 THEN GOSUB 2450 ELSE GOSUB 2440
2430 GOTO *HARF_PRINT
2440 MID$(SEC$(0),P,128)=MID$(SEC$(0),P+1)+SEC$(1):P=129
2450 MID$(SEC$(1),P-128,128)=MID$(SEC$(1),P-127)
2460 BEAM=0:GOSUB *MV_L:BEAM=0:RETURN
2470 GOSUB *DAT_GET:CHNG=DAT:P=1:GOSUB 2440:GOTO *DAT_CHNG
2480 *TAB LOCATE 0,23:GOSUB *KEY_CLR:INPUT "Move Address ? $",A$
2490 IF A$="MAX" OR A$="max" THEN SIZ=MX_SIZ:GOTO 2520
2500 SIZ=VAL("&H"+A$)
2510 IF (INSTR(A$,"0")=0 AND SIZ=0) OR SIZ>MX_SIZ THEN *移禁
2520 REC=BLK:BLK=INT(SIZ/256)+1
2530 Y_SIT=INT((SIZ MOD 256)/16):X_SIT=SIZ MOD 16
2540 IF REC=BLK THEN RETURN ELSE *BLOCK_MOVE
2550 *HOME BEAM=0:X_SIT=0:Y_SIT=0:RETURN
2560 *CLS FOR I=0 TO 1:MID$(SEC$(I),1,128)=STRING$(128,CHR$(0)):NEXT
2570 ED_FLG=1:GOTO *BLOCK_PRINT
2580 *CR BEAM=0:X_SIT=0:GOTO *MV_D
2590 *DUP ASC_FLG=ASC_FLG XOR 1:RETURN
2600 *INS ED_FLG=1:P=Y_SIT*16+X_SIT+1:A$=CHR$(0)
2610 IF Y_SIT>7 THEN 2640
2620 A$=RIGHT$(SEC$(0),1)
2630 MID$(SEC$(0),P,128)=CHR$(0)+MID$(SEC$(0),P):P=129
2640 MID$(SEC$(1),P-128,128)=A$+MID$(SEC$(1),P-128)
2650 BEAM=0:GOTO *HARF_PRINT
2660 *NEXT RES=BLK:BLK=BLK+1:GOTO *BLOCK_MOVE
2670 *BACK RES=BLK:BLK=BLK-1:GOTO *BLOCK_MOVE
2680 *EOF RES=BLK:BLK=0:GOSUB *BLOCK_MOVE
2690 LOCATE 0,23:PRINT "セーブしますか? [Y,N] >";:GOSUB *KEY_CLR
2700 GOSUB *KEY_IN:A=INT(INSTR("_YyNn",KEY_DAT$)/2)
2710 ON A GOTO *SAVE,*END:RETURN
2720 *ESC BEAM=0:MODE=MODE XOR 1:GOTO *MODE_PRINT
2730 *MV_R IF MODE ELSE BEAM=BEAM XOR 1:IF BEAM THEN RETURN
2740 X_SIT=X_SIT+1 AND 15:IF X_SIT=0 THEN *MV_D ELSE RETURN
2750 *MV_L IF MODE ELSE BEAM=BEAM XOR 1:IF BEAM ELSE RETURN
2760 X_SIT=X_SIT-1 AND 15:IF X_SIT=15 THEN *MV_U ELSE RETURN
2770 *MV_U Y_SIT=Y_SIT-1 AND 15:IF Y_SIT=15 THEN *BACK ELSE RETURN
2780 *MV_D Y_SIT=Y_SIT+1 AND 15:IF Y_SIT= 0 THEN *NEXT ELSE RETURN
2790 *DEL BEAM=1:GOSUB *MV_R:BEAM=0:GOTO *BS
2800 '
2810 *HEX_SET A=INT(INSTR(HEXKEY$,KEY_DAT$)/4)-1:IF A<0 THEN RETURN
2820 GOSUB *DAT_GET:MID$(DAT$,BEAM+1,1)=HEX$(A)
2830 CHNG=VAL("&h"+DAT$):GOSUB *DAT_CHNG:GOTO *MV_R
2840 *ASC_SET CHNG=ASC(KEY_DAT$):IF CHNG<32 THEN RETURN
2850 GOSUB *DAT_GET:GOSUB *DAT_CHNG:GOTO *MV_R
2860 *DAT_CHNG
2870 GOSUB *DAT_SET:A=CHNG-DAT:GOSUB *SIZE_CHK
2880 X_SM(Y_SIT)=X_SM(Y_SIT)+A:Z_SM=Z_SM+A
2890 Y_SM(X_SIT)=Y_SM(X_SIT)+A:ED_FLG=1:GOTO *SM_PRINT
2900 '
2910 *KEY_IN KEY_DAT$="":WHILE KEY_DAT$="":KEY_DAT$=INKEY$:WEND:RETURN
2920 *KEY_CLR WHILE INKEY$<>"":WEND:RETURN
2930 *DAT_GET
2940 DAT=FNGET(ASCII$(Y_SIT),X_SIT):DAT$=FNHEX$(DAT):RETURN
2950 *DAT_SET
2960 MID$(ASCII$(Y_SIT),X_SIT+1,1)=CHR$(CHNG):RETURN
2970 *SIZE_CHK
2980 SIZ=BLK*256+Y_SIT*16+X_SIT+1
2990 IF SIZ<=MX_SIZ THEN RETURN
3000 MX_SIZ=SIZ:GOTO *SIZE_PRINT